﻿using System.Collections.Generic;
using System.IO;
using System.Windows.Forms;
using NExplorer.AddIns.Samples;
using NExplorer.AddIns.Samples.Forms;

namespace NExplorer.AddIns.Samples.Commands
{
    /// <summary>
    /// Demonstrates a command that works with many types, but when only one file is selected.
    /// (See <see cref="SampleMenuBuilder"/>.)
    /// </summary>
    internal class PasteClipboardToFileCommand : CommandBase
    {
        internal static readonly List<LowerCaseString> Extensions = new List<LowerCaseString>();

        static PasteClipboardToFileCommand()
        {
            Extensions.Add(LowerCaseString.Empty);
        }

        public PasteClipboardToFileCommand()
            : base("Paste Clipboard to File")
        { }

        //internal static bool 
        protected override void Execute(FileSystemInfo fileSystemInfo)
        {
            PasteClipboardToFileForm form = new PasteClipboardToFileForm();
            form.ShowDialog();


            //FileInfo fileInfo = fileSystemInfo as FileInfo;

            //if (fileInfo != null)
            //{
            //    if (fileInfo.Length > 1024 * 1000)
            //    {
            //        string text = "The file is quite large. Are you sure you want to copy its contents to the clipboard?";

            //        if (MessageBox.Show(text, "Large file", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            //        {
            //            CopyFileToClipboard(fileSystemInfo);
            //        }
            //    }
            //    else
            //    {
            //        CopyFileToClipboard(fileSystemInfo);
            //    }
            //}
        }

        private void CopyFileToClipboard(FileSystemInfo info)
        {
            string text = File.ReadAllText(info.FullName);

            if (text.Length == 0)
            {
                MessageBox.Show("The file is empty and won't be copied.", "Empty File", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                Clipboard.SetText(text);
            }
        }
    }
}